﻿using System;
using System.Collections.Generic;

namespace Ndex.Core
{
    public class Pagination : IPagination
    {
        public string OrderBy { get; set; }
        public bool OrderAscending { get; set; }
        public bool HasPaging { get; set; }
        public int PageSize { get; set; }
        public int Current { get; set; }
        public int NoPages { get; set; }
        public int NoItems { get; set; }
        public bool TakeAll { get; set; }

        public Pagination()
        {
            HasPaging = true;
            NoPages = 0;
            OrderBy = string.Empty;
            PageSize = 25;
            Current = 1;
            NoItems = 0;
            TakeAll = false;
        }

        public int OrderNumber
        {
            get { return OrderAscending ? 1 : 0; }
            set { OrderAscending = value % 2 == 1; }
        }

        public List<NameModel> Pages
        {
            get
            {
                var result = new List<NameModel>();
                var min = Math.Max(1, Current - 5);
                var max = Math.Min(NoPages, min + 10);
                for (var i = min; i <= max; i++)
                    result.Add(new NameModel { Id = i, Name = i.ToString() });
                return result;
            }
        }
    }
}
